<?php
include 'secure/core.php';
include 'user_header.php';
include 'left.php'; 
$sql = "SELECT * FROM `ftp_settings`";          
$res = $ado->exec($sql);
$row_array = mysql_fetch_assoc($res);
$ftp_upload_dir = $settings->getFTPdirectory();
?>
<?php 
if(isset($_POST['submit'])){
        
	$handle=opendir($ftp_upload_dir);
	$flag = 0;
	while (($file_name = readdir($handle))!==false) {
	        if($filename == '..' or $file_name = '.'){
	               continue;
		}
		$flag = 1;
		
			chmod($ftp_upload_dir.$file_name,777);
		 	
			$file_path = $settings->getUploadPath();
		        $time = $file_name;
			$new_file_name = $file_path.$time;
			
			rename($ftp_upload_dir.$file_name,$new_file_name);
			$uploaded_by = $_SESSION['userid'];
			$fileSize = filesize($new_file_name);
			$ip = $_SERVER['REMOTE_ADDR'];
			$date = date('Y-m-d H:i:s');
			
			$sql = "INSERT INTO `uploads` set `file_title` = '$file_name', `uploaded_by`= '$uploaded_by', `file_size` = '$fileSize', `created_date` = '$date' , `file_path` = '$file_path', `status` = '1', `ip_address` = '$ip'"; 
	 $ado->exec($sql);
			
			
		
	}	
	if($flag == 1){
	echo '<script type="text/javascript">
        window.location = "ftp_upload.php?msg=1"
        </script>';
	}else{
	echo '<script type="text/javascript">
        window.location = "ftp_upload.php?msg=2"
        </script>';
	}	
}
?>

		<div id="right">
		<div class="section">
		<?php if($_GET['msg'] == '1') { ?>
		<div class="message green"><span><b>Success</b>: Your file has been successfully uploaded.</span></div>
		<?php } ?>
		<?php if($_GET['msg'] == '2') { ?>
		<div class="message red"><span><b>Error</b>: There was an error uploading your file.</span></div>
		<?php } ?>
				<div class="box">
					<div class="title">
						FTP File Upload
						<span class="hide"></span>
					</div>
					<div class="content">
						<form action="ftp_upload.php" method="POST">
                                                        <div class="row">
								<label>FTP Hostname</label>
								<div class="ftp">
								<div class="right"><input type="text" disabled="disabled" name="userfile" value="<?php echo $row_array['hostname']; ?>"></div>
								</div>
							</div>
							<div class="row">
								<label>FTP Username</label>
								<div class="ftp">
								<div class="right"><input type="text" disabled="disabled" name="userfile" value="<?php echo $row_array['username']; ?>"></div>
								</div>
							</div>
							<div class="row">
								<label>FTP Password</label>
								<div class="ftp">
								<div class="right"><input type="text" disabled="disabled" name="userfile" value="<?php echo $row_array['password']; ?>"></div>
								</div>
							</div>
							<div class="row">
								<label>Click once uploaded</label>
								<div class="right">
								<button type="submit" class="green" name="submit"><span>Submit</span></button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
<?php include 'footer.php'; ?>